<?php
include($folder.'/layouts/code-behind/backend.php');
function blc_cikkek_select($from, $itemsPerPage, $sortColumn, $sortDirection)
{
	$orderBy = $sortColumn.'_'.$sortDirection;
	return
		query(
			'SELECT 
				t.id AS textID,
				t.title AS textTitle,
				DATE_FORMAT(t.created,\'%Y.%m.%d. %H:%i\') AS textCreated,
				tc.description AS textCategoryDescription 
			FROM text AS t 
				LEFT OUTER JOIN textcategory AS tc ON t.textcategory_id = tc.id 
				ORDER BY
					CASE WHEN :orderBy = \'textTitle_asc\' THEN t.title END ASC,
					CASE WHEN :orderBy = \'textTitle_desc\' THEN t.title END DESC,
					CASE WHEN :orderBy = \'textCategoryDescription_asc\' THEN tc.description END ASC,
					CASE WHEN :orderBy = \'textCategoryDescription_desc\' THEN tc.description END DESC,
					CASE WHEN :orderBy = \'textCreated_asc\' THEN DATE_FORMAT(t.created,\'%Y.%m.%d. %H:%i\') END ASC,
					CASE WHEN :orderBy = \'textCreated_desc\' THEN DATE_FORMAT(t.created,\'%Y.%m.%d. %H:%i\') END DESC
				LIMIT :from,:itemsPerPage',
			array('from'=>$from, 'itemsPerPage'=>$itemsPerPage, 'orderBy'=>$orderBy));	
}
function blc_cikkek_select_count()
{
	return queryScalar('SELECT COUNT(1) FROM text', null);
}
?>